<!DOCTYPE html>
<html lang="zh-cn">

<head>

  <meta content="text/html;charset=utf-8" http-equiv="content-type">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">

  <title>滑雪族 - 返利管理</title>

  <!-- Bootstrap Core CSS -->
<!-- MetisMenu CSS -->
<!-- Custom CSS -->
<!-- Custom Fonts -->
  <!-- Timeline CSS -->
  <!-- Morris Charts CSS -->
  <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
  <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
  <!--[if lt IE 9]>
  <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
  <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
  <![endif]-->
  <!-- Bootstrap DateRangePicker CSS -->

    <link rel="stylesheet" href="/server/r/bower_components/bootstrap/dist/css/bootstrap.min.css" />
    <link rel="stylesheet" href="/server/r/bower_components/metisMenu/dist/metisMenu.min.css" />
    <link rel="stylesheet" href="/server/r/static/css/sb-admin-2_e507c2b.css" />
    <link rel="stylesheet" type="text/css" href="/server/r/bower_components/font-awesome/css/font-awesome.min.css" />
    <link type="text/css" rel="stylesheet" href="/server/r/static/css/hxz/common_2baa698.css" />
    <link rel="stylesheet" href="/server/r/static/css/timeline_1c13c9f.css" />
    <link rel="stylesheet" href="/server/r/bower_components/morrisjs/morris.css" />
    <link rel="stylesheet" type="text/css" href="/server/r/bower_components/alertify/themes/alertify.core.css" />
    <link rel="stylesheet" type="text/css" href="/server/r/bower_components/alertify/themes/alertify.bootstrap.css" />
    <link rel="stylesheet" href="/server/r/bower_components/bootstrap-daterangepicker/daterangepicker.css" />
    <link type="text/css" rel="stylesheet" href="/server/r/bower_components/select2/dist/css/select2.min.css" />
</head>

<body>
<div id="wrapper">
  <!-- Navigation -->
  <nav class="navbar navbar-default navbar-static-top" role="navigation" style="margin-bottom: 0">

    <div class="navbar-header">
  <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
    <span class="sr-only">Toggle navigation</span>
    <span class="icon-bar"></span>
    <span class="icon-bar"></span>
    <span class="icon-bar"></span>
  </button>
  <a class="navbar-brand" href="activity-list">滑雪族 管理</a>
</div>
<!-- /.navbar-header -->

<ul class="nav navbar-top-links navbar-right">
  <!-- /.dropdown -->
  <li class="dropdown">
    <a class="dropdown-toggle" data-toggle="dropdown" href="#">
      <i class="fa fa-user fa-fw"></i> <i class="fa fa-caret-down"></i>
    </a>
    <ul class="dropdown-menu dropdown-user">
      <li><a href="/manage/logout"><i class="fa fa-sign-out fa-fw"></i> 退出系统</a>
      </li>
    </ul>
    <!-- /.dropdown-user -->
  </li>
  <!-- /.dropdown -->
</ul>
<!-- /.navbar-top-links -->

    <div class="navbar-default sidebar" role="navigation">
      <div class="sidebar-nav navbar-collapse">
        <ul class="nav" id="side-menu">
  <li>
    <a href="#"><i class="fa fa-asterisk fa-fw"></i> 产品管理<span class="fa arrow"></span></a>
    <ul class="nav nav-second-level">
      <li>
        <a href="/manage/activity-list"> 产品查询</a>
      </li>
      <li>
        <a href="/manage/manage-organizer-render-activity"> 产品显示控制</a>
      </li>
    </ul>
    <!-- /.nav-second-level -->
  </li>
  <li>
    <a href="/#"><i class="fa fa-male fa-fw"></i> 报名管理<span class="fa arrow"></span></a>
    <ul class="nav nav-second-level">
      <li>
        <a href="/manage/player-list"> 报名查询</a>
      </li>
    </ul>
  </li>
  <li>
    <a href="#"><i class="fa fa-list-alt fa-fw"></i> 订单管理<span class="fa arrow"></span></a>
    <ul class="nav nav-second-level">
      <li>
        <a href="/manage/order-list"> 订单查询</a>
      </li>
      <li>
        <a href="/manage/refund-list"> 退款管理</a>
      </li>
    </ul>
    <!-- /.nav-second-level -->
  </li>
  <li>
    <a href="#"><i class="fa fa-check-circle fa-fw"></i> 主办方认证<span class="fa arrow"></span></a>
    <ul class="nav nav-second-level">
      <li>
        <a href="/manage/organizer-edit"> 创建主办方</a>
      </li>
      <li>
        <a href="/manage/organizer-list"> 主办方列表</a>
      </li>
      <li>
        <a href="/manage/organizer-print"> 冬令营打印设置</a>
      </li>

    </ul>
    <!-- /.nav-second-level -->
  </li>
  <li>
    <a href="#"><i class="fa fa-picture-o fa-fw"></i> 雪场管理<span class="fa arrow"></span></a>
    <ul class="nav nav-second-level">
      <li>
        <a href="/manage/ski-field-edit"> 创建雪场</a>
      </li>
      <li>
        <a href="/manage/ski-field-list"> 雪场列表</a>
      </li>

    </ul>
    <!-- /.nav-second-level -->
  </li>
  <li>
    <a href="#"><i class="fa fa-users fa-fw"></i> 教练管理<span class="fa arrow"></span></a>
    <ul class="nav nav-second-level">
      <li>
        <a href="/manage/coach-list"> 预约情况</a>
      </li>
    </ul>
    <!-- /.nav-second-level -->
  </li>
  <li>
    <a href="#"><i class="fa fa-credit-card fa-fw"></i> 结算管理<span class="fa arrow"></span></a>
    <ul class="nav nav-second-level">
      <li>
        <a href="/manage/manage-transfer-list"> 转账管理</a>
      </li>
      <li>
        <a href="/manage/manage-withdrawals-apply-list"> 提现申请</a>
      </li>
      <li>
        <a href="/manage/manage-withdrawals-record-list"> 结算列表</a>
      </li>
    </ul>
    <!-- /.nav-second-level -->
  </li>
  <li>
    <a href="#"><i class="fa fa-rmb fa-fw"></i> 财务管理<span class="fa arrow"></span></a>
    <ul class="nav nav-second-level">
      <li>
        <a href="/manage/stream-list"> 交易流水</a>
      </li>
      <li>
        <a href="/manage/manage-bill-record-list"> 对账列表</a>
      </li>
    </ul>
    <!-- /.nav-second-level -->
  </li>
  <li>
    <a href="#"><i class="fa fa-dollar fa-fw"></i> 营销管理<span class="fa arrow"></span></a>
    <ul class="nav nav-second-level">
      <li>
        <a href="/manage/marketing-list"> 返利管理</a>
      </li>
    </ul>
    <!-- /.nav-second-level -->
  </li>
  <li>
    <a href="#"><i class="fa fa-comments fa-fw"></i> 评价管理<span class="fa arrow"></span></a>
    <ul class="nav nav-second-level">
      <li>
        <a href="/manage/comment-list">评价管理</a>
      </li>
    </ul>
  </li>
  <li>
    <a href="#"><i class="fa fa-tasks fa-fw"></i> 定时处理管理<span class="fa arrow"></span></a>
    <ul class="nav nav-second-level">
      <li>
        <a href="/manage/quartz-list"> 定时处理列表</a>
      </li>
    </ul>
    <!-- /.nav-second-level -->
  </li>
  <li>
    <a href="#"><i class="fa fa-wechat fa-fw"></i> 微信页面管理<span class="fa arrow"></span></a>
    <ul class="nav nav-second-level">
      <li>
        <a href="/manage/typography-list"> 微信首页管理</a>
      </li>
      <li>
        <a href="/manage/activity-weight-manage"> 活动置顶</a>
      </li>
    </ul>
    <!-- /.nav-second-level -->
  </li>
</ul>
      </div>
      <!-- /.sidebar-collapse -->
    </div>
    <!-- /.navbar-static-side -->
  </nav>


  <div class="modal fade" id="choose-data" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
       aria-hidden="true">
    <div class="modal-dialog" style="width: 360px;">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
          <h4 class="modal-title">返利时间</h4>
        </div>
        <div class="modal-body">
          <div id="code1" style="text-align: center;"></div>
          <div class="form-group">
            <div class="form-inline">
              <label>开始时间：</label>
              <input type="hidden" id="start-time" name="startTime">
              <input type="hidden" id="end-time" name="endTime">

              <div class="input-group" id="start-date">
              <span class="input-group-addon">
                <i class="glyphicon glyphicon-calendar fa fa-calendar"></i>
              </span>
                <input type="text" class="form-control input-sm" readonly placeholder="请选择返利时间起点" style="width: 150px;">
              </div>
            </div>
            <div class="form-inline">
              <label>结束时间：</label>

              <div class="input-group" id="end-date">
              <span class="input-group-addon">
                <i class="glyphicon glyphicon-calendar fa fa-calendar"></i>
              </span>
                <input type="text" class="form-control input-sm" readonly placeholder="请选择返利时间终点" style="width: 150px;">
              </div>
            </div>
          </div>

          <div class="form-group" style="text-align: center;">
            <button class="btn btn-sm btn-success" id="sbrCharge-add">确定</button>
          </div>
        </div>
      </div>
      <!-- /.modal-content -->
    </div>
    <!-- /.modal-dialog -->
  </div>

  <div id="page-wrapper">
    <div class="row">
      <div class="col-lg-12">
        <h3 class="page-header">返利管理</h3>
      </div>
      <!-- /.col-lg-12 -->
    </div>
    <!-- /.row -->
    <div class="form-inline">
      <div class="form-group">
        <label>返利规则：</label>
        <input class="form-control input-sm" id="sbr-id" value="默认规则" type="text" readonly>
      </div>

      <div class="form-group">
        <!--<a type="button" class="btn btn-sm btn-success btn-outline">查询</a>-->

      </div>
    </div>


    <div class="row">
      <div class="col-lg-12">
        <div class="panel panel-default">
          <div class="panel-heading">
            筛选雪票
          </div>
          <!-- /.panel-heading -->
          <div class="panel-body">
            <div class="col-lg-6">
              <div class="panel panel-default">
                <!-- /.panel-heading -->
                <div class="panel-body">
                  <div class="form-inline">
                    <div class="form-group">
                      <label>产品：</label>
                      <select class="form-control" id="marketing-activity"></select>
                    </div>
                    <div class="form-group" id="episode-form-group" style="display: none;">
                      <label>子项目：</label>
                      <select class="form-control" id="marketing-episode"></select>
                    </div>
                    <div class="form-group">
                      <a id="market-filter" type="button" class="btn btn-sm btn-success btn-outline">查询</a>
                    </div>
                  </div>

                  <div class="row">
                    <div class="dataTable_wrapper">
                      <table class="table table-striped table-bordered table-hover">
                        <thead>
                        <tr class="warning">
                          <th>ID</th>
                          <th>票名称</th>
                          <th>价格(元)</th>
                          <th>操作</th>
                        </tr>
                        </thead>
                        <tbody id="list-body"></tbody>
                      </table>
                      <div class="pull-right">
                        <button id="market-pre" type="button" class="btn btn-sm btn-success btn-outline">上一页</button>
                        <button id="market-next" type="button" class="btn btn-sm btn-success btn-outline">下一页</button>
                      </div>
                    </div>

                    <!-- /.row -->
                  </div>
                  <!-- /.panel-body -->
                </div>
                <!-- /.panel-body -->
              </div>
              <!-- /.panel -->
            </div>
            <!-- /.col-lg-6 -->
            <div class="col-lg-6">
              <div class="panel panel-default">
                <!-- /.panel-heading -->
                <div class="panel-body">
                  <div class="form-inline">
                    <div class="form-group">
                      <p class="help-block font-small">注意，点击保存营销按钮,将下方列表信息全部保存!</p>
                    </div>
                    <div class="form-group">
                      <a id="market-create" type="button"
                         class="btn btn-sm btn-success btn-outline pull-right">保存营销</a>
                    </div>
                  </div>
                  <div class="row">
                    <div class="dataTable_wrapper">
                      <table class="table table-striped table-bordered table-hover">
                        <thead>
                        <tr class="warning">
                          <th>ID</th>
                          <th>票名称</th>
                          <th>价格(元)</th>
                          <th>成本(元)</th>
                          <th>期望利润(元)</th>
                          <th>操作</th>
                        </tr>
                        </thead>
                        <tbody id="check-list-body"></tbody>
                      </table>
                      <div class="pull-right">
                        <button id="market-check-pre" type="button" class="btn btn-sm btn-success btn-outline">上一页
                        </button>
                        <button id="market-check-next" type="button" class="btn btn-sm btn-success btn-outline">下一页
                        </button>
                      </div>
                    </div>

                    <!-- /.row -->
                  </div>
                </div>
                <!-- /.panel-body -->
              </div>
              <!-- /.panel -->
            </div>
          </div>
        </div>
      </div>
      <!-- /.col-lg-6 -->
    </div>


  </div>
  <!-- /#page-wrapper -->

</div>
<!-- /#wrapper --><script id="tpl-quartz-list-item" type="text/template">
  <tr>
    <td>{{chargeId}}</td>
    <td>{{chargeName}}</td>
    <td>{{price}}</td>
    <td>
      <a type="button" data-code="{{chargeId}}" class="btn btn-info btn-xs detail-charge">选择</a>
    </td>
  </tr>
</script>

<script id="tpl-check-list-item" type="text/template">
  <tr>
    <td>{{chargeId}}</td>
    <td>{{chargeName}}</td>
    <td>{{price}}</td>
    <td><input type="text" value="{{cost}}" data-code="{{chargeId}}" class="cost-sbr-charge"></td>
    <td><input type="text" value="{{profit}}" data-code="{{chargeId}}" class="profit-sbr-charge"></td>
    <td>
      <a type="button" data-code="{{chargeId}}" class="btn btn-info btn-xs delete-sbr-charge">清除</a>
    </td>
  </tr>
</script>
<div id="hxz-background" class="background" style="display: none; "></div>
<div id="hxz-progressBar" class="progressBar" style="display: none; ">数据加载中，请稍等...</div>

<script src="/server/r/require.js"></script>
<script type="text/javascript">/*resourcemap*/
require.config({paths:{
  "r/bower_components/jquery/dist/jquery.min": "/server/r/bower_components/jquery/dist/jquery.min",
  "r/bower_components/underscore/underscore-min": "/server/r/bower_components/underscore/underscore-min",
  "r/static/js/hxz/hxz.valid": "/server/r/static/js/hxz/hxz.valid_12cc206",
  "r/static/js/hxz/hxz.rest": "/server/r/static/js/hxz/hxz.rest_07c8105",
  "r/bower_components/alertify/alertify.min": "/server/r/bower_components/alertify/alertify.min",
  "r/static/js/alertify-config": "/server/r/static/js/alertify-config_0cc8db2",
  "r/bower_components/bootstrap/dist/js/bootstrap.min": "/server/r/bower_components/bootstrap/dist/js/bootstrap.min",
  "r/bower_components/metisMenu/dist/metisMenu.min": "/server/r/bower_components/metisMenu/dist/metisMenu.min",
  "r/bower_components/select2/dist/js/select2": "/server/r/bower_components/select2/dist/js/select2",
  "r/static/js/hxz/hxz.ui": "/server/r/static/js/hxz/hxz.ui_0a7714d",
  "r/static/js/hxz/hxz": "/server/r/static/js/hxz/hxz_589b155",
  "r/bower_components/moment/min/moment-with-zh-cn.min": "/server/r/bower_components/moment/min/moment-with-zh-cn.min",
  "r/vendor/pagination/jquery.pagination": "/server/r/vendor/pagination/jquery.pagination",
  "r/bower_components/bootstrap-daterangepicker/daterangepicker": "/server/r/bower_components/bootstrap-daterangepicker/daterangepicker"
}});

  require(["r/bower_components/jquery/dist/jquery.min", "r/static/js/hxz/hxz", "r/static/js/alertify-config", "r/bower_components/moment/min/moment-with-zh-cn.min", "r/vendor/pagination/jquery.pagination", "r/bower_components/select2/dist/js/select2", "r/bower_components/bootstrap-daterangepicker/daterangepicker"], function ($, hxz, alertify, moment) {
    var pagination = false;
    var chargeIndex = 1;
    var chargeCount = 0;
    var size = 10;
    var sbrChargeCount = 0;
    var sbrChargeIndex = 1;
    var tmpList = [];
    var checkList = [];
    var chooseCharge = {};
    var currentCheckList = [];
    var marketFilter = {};
    var $startDate = $('#start-date');
    var $endDate = $('#end-date');


    var $startDateInput = $('#start-date input');

    var $endDateInput = $('#end-date input');

    var $startTime = $('#start-time');
    var $endTime = $('#end-time');

    function fetchOption() {
      hxz.activityOptionGroup("#marketing-activity", "#marketing-episode", 0, 1);
    }


    function fetchList(page) {
      var apiList = hxz.RestApi.manageChargeList;
      marketFilter.page = page;
      marketFilter.size = size;

      if (marketFilter.activityId === undefined && $("#activityId").val() !== "") {
        marketFilter.activityId = $("#activityId").val();
      }

      if (marketFilter.episodeId === undefined && $("#episodeId").val() !== "") {
        marketFilter.episodeId = $("#episodeId").val();
      }

      hxz.doGet({url: hxz.getUrlByfiterOption(apiList, marketFilter)}, function (data) {

        if (data.status == "0") {
          return alertify.log("系统错误");
        }
        tmpList = data.data.dataList;
        chargeCount = data.data.count;
        render(tmpList);
      });
    }


    function fetchCheckList(page) {
      hxz.doGet({url: hxz.RestApi.manageMarketingCharges}, function (data) {
        if (data.status == "0") {
          return alertify.log("系统错误");
        }
        checkList = data.data;
        sbrChargeCount = checkList.length;
        var startIndx = (sbrChargeIndex - 1) * size;
        var endIndex = sbrChargeIndex * size;
        if (endIndex > sbrChargeCount) {
          endIndex = sbrChargeCount;
        }
        var curIndex = _.range(startIndx, endIndex);
        _.each(curIndex, function (index) {
          currentCheckList.push(checkList[index]);
        });

        renderCheck(currentCheckList);
      });
    }

    function render(dataList) {
      var tpl = _.template($('#tpl-quartz-list-item').html());
      $("#list-body").html("");
      for (var i = 0; i < dataList.length; i++) {
        var _data = dataList[i];
        $("#list-body").append(tpl(_data));
      }

    }

    function renderCheck(dataList) {
      var tpl = _.template($('#tpl-check-list-item').html());
      $("#check-list-body").html("");
      for (var i = 0; i < dataList.length; i++) {
        var _data = dataList[i];
        $("#check-list-body").append(tpl(_data));
      }
    }

    function event() {


      $("#sbrCharge-add").on("click", function () {

        var data = {
          charges: JSON.stringify([chooseCharge])
        };
        if ($startTime.val() != "") {
          data.startTime = $startTime.val();
        }
        if ($endTime.val() != "") {
          data.endTime = $endTime.val();
        }
        if ($startTime.val() != "" && $endTime.val() != "") {
          if ($startTime.val() > $endTime.val() != "") {
            return alertify.log("预约检索的开始时间不能大于结束时间！");
          }
        }
        hxz.doPost({url: hxz.RestApi.manageMarketingSave, data: data}, function (data) {

          if (data.status == "0") {
            return alertify.log("系统错误");
          } else {
            $("#choose-data").modal("hide");
            sbrChargeCount++;
            checkList.unshift(chooseCharge);
            tmpList = _.difference(tmpList, [chooseCharge]);
            var startIndx = (sbrChargeIndex - 1) * size;
            var endIndex = sbrChargeIndex * size;
            if (endIndex > sbrChargeCount) {
              endIndex = sbrChargeCount;
            }
            var curIndex = _.range(startIndx, endIndex);
            currentCheckList = [];
            _.each(curIndex, function (index) {
              currentCheckList.push(checkList[index]);
            });
            renderCheck(currentCheckList);
            render(tmpList);
            return alertify.log("添加雪票到营销活动中！");
          }
        });
      });
      $("#list-body").on("click", ".detail-charge", function () {
        var dataCharge = {
          chargeId: $(this).data("code")
        };
        var date = new Date();
        $startDateInput.val(hxz.datetime(date));
        $startTime.val(date.getTime());
        $endDateInput.val(hxz.datetime(date));
        $endTime.val(date.getTime());
        var obj = _.findWhere(tmpList, dataCharge);
        chooseCharge = obj;
        $("#choose-data").modal("show");
      });


      $("#check-list-body").on("click", ".delete-sbr-charge", function () {
        var data = {
          chargeId: $(this).data("code")
        };
        var obj = _.findWhere(checkList, data);
        hxz.doPost({url: hxz.RestApi.manageSbrChargesDelete, data: data}, function (data) {
          if (data.status == "0") {
            return alertify.log("系统错误");
          } else {
            sbrChargeCount--;
            checkList = _.difference(checkList, [obj]);
//            tmpList.unshift(obj);
//            render(tmpList);

            fetchList(chargeIndex);
            var startIndx = (sbrChargeIndex - 1) * size;
            if (startIndx == sbrChargeCount) {
              sbrChargeIndex = 1;
            }
            startIndx = (sbrChargeIndex - 1) * size;
            var endIndex = sbrChargeIndex * size;
            if (endIndex > sbrChargeCount) {
              endIndex = sbrChargeCount;
            }
            var curIndex = _.range(startIndx, endIndex);
            currentCheckList = [];
            _.each(curIndex, function (index) {
              currentCheckList.push(checkList[index]);
            });
            renderCheck(currentCheckList);
            return alertify.log("成功将活动票移除营销活动");
          }
        });
      });
      $("#check-list-body").on("keyup", ".cost-sbr-charge", function () {
        var data = {
          chargeId: $(this).data("code")
        };
        var obj = _.findWhere(checkList, data);
        obj.cost = $(this).val();
        if (Number(obj.price) < Number(obj.cost)) {
          return alertify.error("警告：你输入的成本大于售出价格！");
        }
      });


      $("#check-list-body").on("keyup", ".profit-sbr-charge", function () {
        var data = {
          chargeId: $(this).data("code")
        };
        var obj = _.findWhere(checkList, data);
        obj.profit = $(this).val();
        if (Number(obj.price) - Number(obj.cost) < Number(obj.profit)) {
          return alertify.error("警告：你输入的期望利润成本大于利润！");
        }
      });

      $("#market-pre").unbind("click").on("click", function () {
        if (chargeIndex == 1) {
          return alertify.log("当前是第一页！");
        } else {
          fetchList(--chargeIndex);
        }
      });

      $("#market-next").unbind("click").on("click", function () {
        var pageInt = parseInt((chargeCount - 1) / size + 1);
        if (chargeIndex >= pageInt) {
          return alertify.log("当前是最后一页！");
        } else {
          fetchList(++chargeIndex);
        }
      });

      $("#market-check-pre").unbind("click").on("click", function () {
        if (sbrChargeIndex == 1) {
          return alertify.log("当前是第一页！");
        } else {
          sbrChargeIndex--;
          var startIndx = (sbrChargeIndex - 1) * size;
          var endIndex = sbrChargeIndex * size;
          if (endIndex > sbrChargeCount) {
            endIndex = sbrChargeCount;
          }
          var curIndex = _.range(startIndx, endIndex);
          currentCheckList = [];
          _.each(curIndex, function (index) {
            currentCheckList.push(checkList[index]);
          });

          renderCheck(currentCheckList);
        }
      });

      $("#market-check-next").unbind("click").on("click", function () {
        var pageInt = parseInt((sbrChargeCount - 1) / size + 1);
        if (sbrChargeIndex >= pageInt) {
          return alertify.log("当前是最后一页！");
        } else {
          sbrChargeIndex++;
          var startIndx = (sbrChargeIndex - 1) * size;
          var endIndex = sbrChargeIndex * size;
          if (endIndex > sbrChargeCount) {
            endIndex = sbrChargeCount;
          }
          var curIndex = _.range(startIndx, endIndex);
          currentCheckList = [];
          _.each(curIndex, function (index) {
            currentCheckList.push(checkList[index]);
          });

          renderCheck(currentCheckList);
        }
      });

      $("#market-create").unbind("click").on("click", function () {
        var data = {
          charges: JSON.stringify(checkList)
        };

//        if ($startTime.val() != "") {
//          data.startTime = $startTime.val();
//        }
//        if ($endTime.val() != "") {
//          data.endTime = $endTime.val();
//        }
//        if ($startTime.val() != "" && $endTime.val() != "") {
//          if ($startTime.val() > $endTime.val() != "") {
//            return alertify.log("预约检索的开始时间不能大于结束时间！");
//          }
//        }
        hxz.doPost({url: hxz.RestApi.manageMarketingSave, data: data}, function (data) {
          if (data.status == "0") {
            return alertify.log("系统错误");
          } else {
            return alertify.log("保存营销信息成功");
          }
        });
      });

      $("#market-filter").unbind("click").on("click", function () {
        marketFilter = {};
        marketFilter.activityId = ($("#marketing-activity").val() === "0") ? "" : $("#marketing-activity").val();
        marketFilter.episodeId = ($("#marketing-episode").val() === "0") ? "" : $("#marketing-episode").val();
        pagination = true;
        fetchList(1);
      });

      moment.locale('zh-cn');
      var commDateConfig = {
        startDate: new Date(),
        timePicker: true,
        timePickerIncrement: 1,
        timePicker24Hour: true,
        locale: {
          format: 'YYYY年MM月DD日',
          separator: ' - ',
          applyLabel: '确定',
          cancelLabel: '关闭',
          weekLabel: 'W',
          customRangeLabel: 'Custom Range',
          daysOfWeek: moment.weekdaysMin(),
          monthNames: moment.monthsShort(),
          firstDay: moment.localeData().firstDayOfWeek()
        }
      };
      commDateConfig.singleDatePicker = true;


      $startDate.daterangepicker(commDateConfig, function (start, end, label) {
        $startDateInput.val(hxz.datetime(start));
        var sDate = new Date(start);
        $startTime.val(sDate.getTime());
      });


      $endDate.daterangepicker(commDateConfig, function (start, end, label) {
        $endDateInput.val(hxz.datetime(start));
        // start 和 end 是moment对象
        var sDate = new Date(start);
        $endTime.val(sDate.getTime());
      });
      var date = new Date();
      $startDateInput.val(hxz.datetime(date));
      $startTime.val(date.getTime());
      $endDateInput.val(hxz.datetime(date));
      $endTime.val(date.getTime());
    }

    pagination = true;
    fetchOption();
    event();
    fetchList(1);
    fetchCheckList(1);
  });


</script>
</body>

</html>